<template>
  <div class="section-wrap">
    <!-- 头部 -->
    <div class="headerBox">
    <div class="header">
      <x-icon type="ios-arrow-left" size="" class="icon-white" @click="goBack"></x-icon>执行检查（组长）
    </div>
    </div>
    <div class="form-section" style="margin-top: 40px;">
      <div class="form-item form-item-style1">
            <div class="label-title">
            <label>检查编号</label>
            </div>
            <div class="input_div">
            <input type="text" value="HR123456789">
            </div>
        </div>
            <div class="form-item form-item-style1">
                <div class="label-title">
                <label>被检查单位</label>
                </div>
                <div class="input_div">
                <input type="text" value="XX项目">
                </div>
            </div>
            <div class="form-item form-item-style1">
                <div class="label-title">
                <label>检查类型</label>
                </div>
                <div class="input_div">
                <input type="text" value="日常检查">
                </div>
            </div>
            <div class="form-item form-item-style1">
                <div class="label-title">
                <label>检查时间</label>
                </div>
                <div class="input_div">
                <input type="text" value="2018-05-24">
                </div>
            </div>

      <div class="info_div3">
        <p>考核分工<span>（2组）</span></p>
        <x-icon type="ios-arrow-up" size="22" class="icon-up"></x-icon>
      </div>
      <div class="member_div">
        <ul class="member_list">
          <li v-for="item in detailinfo.divisionList" :key="item.id">
            <div class="form-item form-item-style1">
              <div class="label-title">
                <label>成员：</label>
              </div>
              <div class="input_div">
                <input type="text" class="member1"
                       value="张里"
                       disabled>
              </div>
            </div>
            <div class="form-item form-item-style1" style="border-bottom: none;">
              <div class="label-title">
                <label>分工（考核项）：</label>
              </div>
              <div class="input_div">
                <input type="text" v-model="item.standardNameList"
                       placeholder="请选择"
                       :disabled="isDisabled">
                <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
              </div>
            </div>
          </li>
          <li v-for="item in detailinfo.divisionList" :key="item.id">
            <div class="form-item form-item-style1">
              <div class="label-title">
                <label>成员：</label>
              </div>
              <div class="input_div">
                <input type="text" class="member2"
                       value="周丽丽"
                       disabled>
              </div>
            </div>
            <div class="form-item form-item-style1" style="border-bottom: none;">
              <div class="label-title">
                <label>分工（考核项）：</label>
              </div>
              <div class="input_div">
                <input type="text" v-model="item.standardNameList"
                       placeholder="请选择"
                       :disabled="isDisabled">
                <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
              </div>
            </div>
          </li>
        </ul>
      </div>

      <div class="notice_div" style="display:;">
        <div class="notice_top">
          <p>检查记录<span>（3条）</span></p>
          <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
        </div>
        <ul class="notice_list">
          <li>
            <div class="down_div">
              <label>安全管理</label>
              <div class="notice_item">
                <span class="notice_number">2</span>
                <x-icon type="ios-arrow-up" size="22" class="icon-up"></x-icon>
              </div>
            </div>
            <ul class="cList">
              <li class="clearfix">
                <p>1.国家电网公司贯彻落实《中共中央国务院关于推进安全生产领域改革发展的意见》的实施方案（国家电网办〔2017〕1101号）、省公司“本质安全•三年登
                    高”工作方案、2018年安全工作会议精神及2018年安全工作意见传达贯彻情况。</p>
                <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
              </li>
              <li class="clearfix">
                <p>2.安全管理体系是否健全，安全责任界面和工作职责是否厘清，安全管理制度是否完善，安全工作流程是否优化。</p>
                <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
              </li>
            </ul>
          </li>
          <li>
            <div class="down_div">
              <label>安全责任</label>
              <div class="notice_item">
                <span class="notice_number">1</span>
                <x-icon type="ios-arrow-up" size="22" class="icon-up"></x-icon>
              </div>
            </div>
            <ul class="cList">
              <li class="clearfix">
                <p>1.是否按照《安全隐患排查治理管理办法》要求，建立完善安全隐患排查治理常态工作机制。</p>
                <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
              </li>
            </ul>
          </li>
        </ul>
      </div>

      <div class="details">
        <div class="details_top">
          <p>生成通知单</p>
          <x-icon type="ios-arrow-up" size="22" class="icon-up"></x-icon>
        </div>
        <ul class="details_list">
          <li>
            <label>生成隐患整改通知单</label>
            <div class="details_item">
              <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
            </div>
          </li>
          <!-- <li>
            <label>生成设备停用通知单</label>
            <div class="details_item">
              <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
            </div>
          </li>
          <li>
            <label>生成停工通知单</label>
            <div class="details_item">
              <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
            </div>
          </li> -->
        </ul>
        <!-- <tree-classify :classify-list="detailinfo.divisionList[0].classifyList" :keyList="detailinfo.divisionList[0].recordItemList" @popupStandard="popupStandard"></tree-classify> -->
      </div>

      <div class="btns_div">
        <a class="submitBtn" @click.native="submitRecord(1)">提 交</a>
      </div>
    </div>
    <div v-transfer-dom id="aaa">
      <popup v-model="classValue" width="100%" >
        <select-depart @nodeClick='selectedDepart'></select-depart>
      </popup>
       <popup v-model="standard" width="100%">
        <select-depart @nodeClick='selectedDepart'></select-depart>
      </popup>
    </div>
  </div>
</template>
<script>
import selectDepart from "@commonComponents/selectDepart/selectDepart";
import treeClassify from "@commonComponents/treeClassify";
import { TransferDom, Popup, PopupPicker, XButton, AlertModule } from "vux";
export default {
  directives: {
    TransferDom
  },
  data() {
    return {
      startDate: "",
      classValue: false,
      isDisabled: true, // 是否禁止输入
      tableTypeList: [],
      tableList: [],
      detailinfo: {
        createUser: "",
        createDate: "2019-08-29T08:42:15.938Z",
        operUser: "",
        operDate: "2019-08-29T08:42:15.938Z",
        checkDepartId: "",
        checkDepartName: "",
        charge: "", //单位负责人
        classifyOneId: [],
        classifyOneName: "",
        classifyTwoId: [],
        classifyTwoName: "",
        checkDate: "",
        checkGroupLeaderId: "",
        checkGroupLeaderName: "",
        receiverId: "",
        receivrtName: "",
        checkNo: "",
        status: 0,
        approvalResult: "",
        approvalRemark: "",
        approver: "",
        pproverId: "",
        approvalDate: "",
        rocordId: "",
        rocordNotPlan: 0,
        rocordStatus: 0,
        checkScore: 0,
        deleteTag: 0,
        deleteUser: "",
        deleteDate: "",
        beDepartId: "", //被考核单位id
        beDepartName: "", //被考核单位
        divisionList: [
          {
            planId: "",
            divisionProsonId: "",
            divisionProsonName: "",
            standardIdList: "",
            standardNameList: "",
            status: 0,
            editStatus: true,
            recordItemList: [{}],
            classifyList: [{}],
            canAudit: true,
            id: "string"
          }
        ],
        allowApproval: true,
        id: ""
      },
      standard: false,
      classList: [],
      id: "",
      isfirst: false
    };
  },
  components: { selectDepart, Popup, PopupPicker, treeClassify, XButton },
  created() {
    this.getInfo();
  },
  methods: {
    getInfo() {
      let that = this;
      that.isfirst = true;
      that.$axiosAjax
        .getTableTypeList({ parentId: "0", year: new Date().getFullYear })
        .then(res => {
          let typeList = res.data.result.data;
          that.tableTypeList = [[]];
          typeList.forEach(item => {
            that.tableTypeList[0].push({
              name: item.quantizeName,
              value: item.id,
              children: item.children
            });
          });
          that.id = this.$route.query.id;
          if (!that.id) {
            that.id = "";
          }
          that.$axiosAjax.getRecordInfo({ id: that.id }).then(res => {
            that.detailinfo = res.data.result;
            if (!that.detailinfo.classifyOneId) {
              that.detailinfo.classifyOneId = [];
            } else {
              that.detailinfo.classifyOneId = [that.detailinfo.classifyOneId];
              let temp = that.tableTypeList[0].filter(
                x => x.value == that.detailinfo.classifyOneId[0]
              );
              if (temp.length == 1) {
                that.tableList = [[]];
                temp[0].children.forEach(item => {
                  that.tableList[0].push({
                    name: item.quantizeName,
                    value: item.id
                  });
                });
              }
            }
            if (!that.detailinfo.classifyTwoId) {
              that.detailinfo.classifyTwoId = [];
            } else {
              that.detailinfo.classifyTwoId = [that.detailinfo.classifyTwoId];
            }
            if (that.detailinfo.checkDate) {
              that.startDate = that.detailinfo.checkDate.substr(0, 10);
            }
            that.isfirst = false;
          });
        });
    },
    goBack() {
      this.$router.go(-1);
    },
    getCompany() {
      this.classValue = true;
    },
    selectedDepart(data) {
      console.log(1112);
      this.detailinfo.beDepartId = data.id;
      this.detailinfo.beDepartName = data.departName;
      this.detailinfo.charge = data.charge;
      this.classValue = false;
    },
    changeClassifyOne(val) {
      let that = this;
      if (val) {
        let temp = that.tableTypeList[0].filter(
          x => x.value == that.detailinfo.classifyOneId[0]
        );
        if (temp.length == 1) {
          that.tableList = [[]];
          temp[0].children.forEach(item => {
            that.tableList[0].push({
              name: item.quantizeName,
              value: item.id
            });
          });
        }
      }
    },
    changeClassifyTwo(val) {
      let that = this;
      if (val) {
        debugger;
        that.$axiosAjax
          .getQuantizeStandardTreeList({
            classifyId: that.detailinfo.classifyTwoId[0]
          })
          .then(res => {
            that.detailinfo.divisionList[0].recordItemList = res.data.result;
            let idlist = [];
            let nameList = [];
            for (let item of res.data.result) {
              if (item.commonList.length > 0) {
                idlist = idlist.concat(item.commonList.map(i => i.id));
                nameList.push(item.quantizeName);
              }
            }
            that.detailinfo.divisionList[0].standardNameList = nameList.join(
              ";"
            );
            that.detailinfo.divisionList[0].standardIdList = idlist.join(";");
            that.$axiosAjax
              .getQuantizeClassifyStandardList({
                classifyId: that.detailinfo.classifyTwoId[0]
              })
              .then(res => {
                debugger;
                that.detailinfo.divisionList[0].classifyList = res.data.result;
                that.$forceUpdate();
              });
          });
      }
    },
    popupStandard(val) {
      this.standard = true;
    },
    submitRecord(status) {
      let that = this;
      debugger;
      if (that.valid()) {
        that.detailinfo.rocordStatus = status;
        if (that.id) {
          that.$axiosAjax
            .updateQuantizeCheckRecord(that.detailinfo)
            .then(res => {
              that.$router.push("./quanRecord");
            });
        } else {
          that.$axiosAjax
            .createQuantizeCheckRecord(that.detailinfo)
            .then(res => {
              that.$router.push("./quanRecord");
            });
        }
      }
    },
    valid() {
      debugger;
      let that = this;
      if (!that.detailinfo.beDepartId) {
        AlertModule.show({
          title: "验证信息",
          content: "请选择被考核单位",
          hideOnBlur: true
        });
        return false;
      }
      if (!that.detailinfo.classifyOneId) {
        AlertModule.show({
          title: "验证信息",
          content: "请选择考核表类型",
          hideOnBlur: true
        });
      }
      if (!that.detailinfo.classifyTwoId) {
        AlertModule.show({
          title: "验证信息",
          content: "请选择考核表名称",
          hideOnBlur: true
        });
        return false;
      }
      if (!that.detailinfo.checkDate) {
        AlertModule.show({
          title: "验证信息",
          content: "请选择量化考核时间",
          hideOnBlur: true
        });
        return false;
      }
      for (let classify of that.detailinfo.divisionList[0].recordItemList) {
        for (let item of classify.commonList) {
          if (item.actualScore == undefined && item.isMissingItem == 0) {
            AlertModule.show({
              content: "请输入" + item.keyRequire + "实际得分!"
            });
            return false;
          }
          if (item.actualScore != item.shouldScore && !item.deductionReason) {
            AlertModule.show({
              content: "请输入" + item.keyRequire + "扣分原因!"
            });
            return false;
          }
        }
      }
      return true;
    }
  }
};
</script>
<style lang="less" scoped>
.form-section{
    margin-bottom:0;
}
.form-item {
  .input_div {
    .vux-x-icon {
      fill: #999;
      float: right;
      margin-top: 17px;
    }
  }
}

.info_div3 {
  height: 55px;
  line-height: 45px;
  padding: 0 20px;
  border-top: 10px solid #ebeef2;
  p {
    float: left;
    color: #469b7a;
    font-size: 16px;
    font-weight: bold;
    span{
      color: #999;
      font-weight: bold;
    }
  }

  .vux-x-icon {
    fill: #999;
    float: right;
    margin-top: 12px;
  }
}

.member_div {
  .member_list {
    li {
      border-top: 5px solid #ebeef2;
    }

    .member1 {
      color: #ff0000;
    }

    .member2 {
      color: #15bd84;
    }
  }
}

.notice_div {
  border-top: 10px solid #ebeef2;
  padding-left: 20px;
  .notice_top {
    border-bottom: 1px solid #ebeef2;
    height: 45px;
    line-height: 44px;
    padding-right: 20px;
    p {
      float: left;
      color: #469b7a;
      font-size: 16px;
      font-weight: bold;
      span{
        color: #999;
        font-weight: bold;
      }
    }

    .vux-x-icon {
      fill: #999;
      float: right;
      margin-top: 12px;
    }
  }

  .notice_list {
    >li {
      .down_div{
        justify-content: space-between;
        border-bottom: 1px solid #ebeef2;
        height: 55px;
        padding-right: 20px;
        label {
          display: block;
          float: left;
          height: 54px;
          line-height: 54px;
          font-weight: bold;
        }

        .notice_item {
          float: right;
          .notice_number {
            background: #469b7a;
            color: #fff;
            height: 16px;
            width: 16px;
            border-radius: 50%;
            display: inline-block;
            text-align: center;
            line-height: 16px;
            font-size: 12px;
            margin-top: 19px;
          }

          .vux-x-icon {
            fill: #999;
            float: right;
            margin-top: 16px;
          }
        }
      }
      .cList{
        li{
          justify-content: space-between;
          border-bottom: 1px solid #ebeef2;
          align-items: center;
          display: flex;
          padding: 20px 13px 20px 0;
          font-size: 14px;
          p{
            float: left;
            width: calc(100% - 40px);
            line-height: 26px;
          }
          .vux-x-icon {
            fill: #999;
            float: right;
          }
        }
      }
    }

    li:last-child {
      border-bottom: none;
    }
  }
}

.details {
  border-top: 10px solid #ebeef2;
  .details_top {
    border-bottom: 1px solid #ebeef2;
    height: 45px;
    line-height: 44px;
    padding-right: 20px;
    margin-left: 20px;
    background: #fff;
    p {
      float: left;
      color: #469b7a;
      font-size: 16px;
      font-weight: bold;
    }

    .vux-x-icon {
      fill: #999;
      float: right;
      margin-top: 12px;
    }
  }

  .details_list {
    padding-left: 20px;
    .vux-x-icon {
      fill: #999;
      float: right;
      margin-top: 16px;
    }

    li {
      justify-content: space-between;
      border-bottom: 1px solid #ebeef2;
      height: 55px;
      padding-right: 20px;
      label {
        display: block;
        float: left;
        height: 54px;
        line-height: 54px;
      }

      .details_item {
        float: right;
        .vux-x-icon {
          fill: #999;
          float: right;
          margin-top: 16px;
        }
      }
    }

    li:last-child {
      border-bottom: none;
    }
  }
}

.btns_div {
  background: #ebeef2;
  padding: 30px 20px 55px;
  justify-content: center;
  display: flex;
  a {
    height: 40px;
    border-radius: 20px;
    display: inline-block;
    width: 140px;
    text-align: center;
    line-height: 40px;
    color: #fff;
  }

  .saveBtn {
    background: #469b7a;
    width: 45%;
  }

  .submitBtn {
    background: #469b7a;
    width: 70%;
  }
}

.weui-btn + .weui-btn {
  margin-top: 0;
  content: "viewport-units-buggyfill; margin-top: 4vw";
}
.weui-dialog {
  background-color: pink;
}
.vux-alert .vux-x-dialog .weui-mask {
  z-index: 1;
}
.vux-alert .vux-x-dialog .weui-dialog {
}
.vux-popup-dialog {
}
.vux-popup-mask.vux-popup-show {
  z-index: 0 !important;
}
// vux-popup-dialog vux-popup-bottom vux-popup-show
</style>
